package com.ld.security.server.admin.modules.ge.api;


import com.ld.security.auth.shiro.util.LoginUtil;
import com.ld.security.common.mybatis.base.po.IdPo;
import com.ld.security.common.mybatis.base.vo.DataVo;
import com.ld.security.common.mybatis.base.vo.ListVo;
import com.ld.security.common.tomcat.anno.AjaxLogKey;
import com.ld.security.common.tomcat.base.api.SuperApi;
import com.ld.security.server.admin.modules.ge.entity.GeProjectUserRelEntity;
import com.ld.security.server.admin.modules.ge.service.IGeProjectUserRelService;
import com.ld.security.server.admin.modules.ge.vo.ProjectUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@Api(tags="工程用户关联Api管理")
@RequestMapping("/api/geProjectUserRel")
public class GeProjectUserRelApi  extends SuperApi<GeProjectUserRelEntity>{

        @Autowired
        IGeProjectUserRelService iGeProjectUserRelService;
    @AjaxLogKey
  @ApiOperation("得到现在的工程")
  @RequestMapping(value = "/getNowProject", method = RequestMethod.POST)
  public DataVo getNowProject() {
          String userId = LoginUtil.getUserId();
          GeProjectUserRelEntity projectEntity =  iGeProjectUserRelService.getDef(userId);

          return DataVo.of(projectEntity);
  }
    @AjaxLogKey
                @ApiOperation("得到参与的工程")
        @RequestMapping(value = "/getProjects",method = RequestMethod.POST)
        public DataVo getProject() {
                String userId = LoginUtil.getUserId();

                List<ProjectUserVo> list = iGeProjectUserRelService.getProject(userId);

                ListVo vo =  ListVo.of(list);

                return DataVo.of(vo);
        }

        @ApiOperation("切换工程")
        @RequestMapping(value = "/useProject",method = RequestMethod.POST)

        public DataVo useProject(@RequestBody IdPo po){
                String userId = LoginUtil.getUserId();

                iGeProjectUserRelService.useProjectt(po.getId(),userId);
                return DataVo.ofMsg("切换工程成功");
        }

        }
